package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallPointsProductRedeemRecordModel;
import com.mallcloud.mall.mall.api.entity.vo.MallPointsProductRedeemRecordVO;
import com.mallcloud.mall.mall.api.entity.vo.MallPointsRedeemRecordExcelVO;
import com.mallcloud.mall.mall.service.MallPointsProductRedeemRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-积分商品兑换记录")
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/pointsProductRedeemRecord")
public class MallPointsProductRedeemRecordController {
	private final MallPointsProductRedeemRecordService pointsProductRedeemRecordService;

	@ApiOperation("分页")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductredeemrecord_view')")
	public R<IPage<MallPointsProductRedeemRecordVO>> page(Page page, MallPointsProductRedeemRecordModel model) {
		return R.ok(pointsProductRedeemRecordService.pagePointsRedeemRecord(page, model));
	}

	@ApiOperation("查询详情")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductredeemrecord_view')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(pointsProductRedeemRecordService.getById(id));
	}

	@ApiOperation("新增")
	@PostMapping("/save")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductredeemrecord_add')")
	public R save(@RequestBody MallPointsProductRedeemRecordModel pointsRedeemRecord) {
		return R.ok(pointsProductRedeemRecordService.save(pointsRedeemRecord));
	}

	@ApiOperation("修改")
	@PostMapping("/update")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductredeemrecord_edit')")
	public R updateById(@RequestBody MallPointsProductRedeemRecordModel pointsRedeemRecord) {
		return R.ok(pointsProductRedeemRecordService.updateById(pointsRedeemRecord));
	}

	@ApiOperation("领取")
	@PostMapping("/draw")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductredeemrecord_edit')")
	public R draw(@RequestBody List<Long> ids) {
		return R.ok(pointsProductRedeemRecordService.draw(ids));
	}

	@ApiOperation("删除")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductredeemrecord_del')")
	public R removeById(@PathVariable String id) {
		return R.ok(pointsProductRedeemRecordService.removeById(id));
	}

	@ApiOperation("导出兑换记录")
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductredeemrecord_export')")
	public List<MallPointsRedeemRecordExcelVO> export(MallPointsProductRedeemRecordModel dto) {
		return pointsProductRedeemRecordService.export(dto);
	}
}
